package eu.jpereira.trainings.designpatterns.structural.facade;

import eu.jpereira.trainings.designpatterns.structural.facade.model.*;
import eu.jpereira.trainings.designpatterns.structural.facade.service.*;

public class DefaultBooktoreFacade implements BookstoreFacade{
    BookDBService bookDBService;
    CustomerDBService customerDBService;
    CustomerNotificationService customerNotificationService;
    OrderingService orderingService;
    WharehouseService warehouseService;
	
	@Override
	public void placeOrder(String customerId, String isbn) {
		Customer customer = customerDBService.findCustomerById(customerId);
		Book book = bookDBService.findBookByISBN(isbn);
		
		Order order = orderingService.createOrder(customer, book);
		customerNotificationService.notifyClient(order);
		
		DispatchReceipt dispatchReceipt = warehouseService.dispatch(order);
		customerNotificationService.notifyClient(dispatchReceipt);	
	}
	
	public void setServices(WharehouseService ws, OrderingService os, CustomerNotificationService cns,
			CustomerDBService cdbs, BookDBService bdbs){
		
		customerDBService = cdbs;
		bookDBService = bdbs;
		orderingService = os;
		customerNotificationService = cns;
		warehouseService = ws;
	}

}
